// created on 16/12/2003 at 14:46


namespace Orz.LogManager
{
	//========================================================================
	// 	Imported Namespaces
	//========================================================================

	using System;
	using System.IO;
	using Orz.LogManager;
	

	
	public class LocalFileStream : ILogManagerStream
	{
		//================================================================
		// 	Private Data Members
		//================================================================
		
		/// <summary>The file object</summary>
		private FileStream file = null;
		
		/// <summary>The main stream reader</summary>
		private StreamReader stream = null;
		
		
		
		//================================================================
		// 	Constructors
		//================================================================

		///
		/// <summary>
		/// Opens a new stream reader on the given file.
		/// </summary>
		/// <remarks>
		/// When the stream is opened, its current position is moved to the end.
		/// </remarks>
		///
		public LocalFileStream (string sPath_p)
		{
			file = new FileStream (sPath_p, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
			stream = new StreamReader (file);
			SeekToEnd();
		}
		
		
		
		///
		/// <summary>
		/// Positions the next read at the start of the file stream.
		/// </summary>
		///
		public void SeekToStart()
		{
			stream.BaseStream.Seek(0, SeekOrigin.Begin);
		}
		
		
		
		///
		/// <summary>
		/// Positions the next read at the end of the file stream.
		/// </summary>
		/// <remarks>
		/// Any data that has not yet been read will be skipped.
		/// </remarks>
		///
		public void SeekToEnd()
		{
			stream.BaseStream.Seek(0, SeekOrigin.End);
		}
		
		
		///
		/// <summary>
		/// Returns any text between the current read position and the end of 
		/// the file.
		/// </summary>
		///
		public string ReadToEnd()
		{
			return stream.ReadToEnd();
		}
		
		
		///
		/// <summary>
		/// Closes the <code>StreamReader</code> and <code>FileStream</code> objects.
		/// </summary>
		///
		public void Close()
		{
			if (null != stream)
			{
				stream.Close();
				stream = null;
			}
			
			if (null != file)
			{
				file.Close();
				file = null;
			}
		}
	}
}
